package com.gxa.controller.asset;

import com.github.pagehelper.PageInfo;
import com.gxa.common.utils.R;
import com.gxa.entity.asset.AuthApply;
import com.gxa.entity.asset.CheckApply;
import com.gxa.entity.asset.search.CheckApplyAndRecordSearchMap;
import com.gxa.service.asset.CheckApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static com.gxa.common.utils.R.error;
import static com.gxa.common.utils.R.ok;

/**
 * @Description:
 * @Author: zhuiyi
 * @CreatTime: 2022/10/13 16:24
 **/
@Api(tags = "设备检定--->检定申请")
@RestController
@RequestMapping("/check-apply")
public class CheckApplyController {

    @Autowired
    private CheckApplyService service;

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("检定申请列表接口")
    @GetMapping("/list")
    public R queryAll(CheckApplyAndRecordSearchMap map){
        System.out.println("map:---------"+map);
        PageInfo<CheckApply> page = service.queryByPage(map);
        return ok("successs").put("data",page);
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("新增检定申请接口")
    @PostMapping("/add")
    public R add(@RequestBody CheckApply device){
        boolean save = service.save(device);
        if (save){
            return R.ok("添加成功！");
        }
        return error("add error");
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("删除检定申请接口")
    @DeleteMapping("/del/{id}")
    public R del(@PathVariable("id") Integer id){
        boolean b = service.removeById(id);
        if(b){
            R.ok("删除成功！");
        }
        return error("del error");
    }
    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("根据id查询检定申请接口")
    @GetMapping("/queryById/{id}")
    public R queryById(@PathVariable("id") Integer id){
        CheckApply ck = service.getById(id);
        if(ck != null){
            return R.ok("查询成功！").put("data",ck);
        }
        return error("query error");
    }
    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("编辑检定申请接口")
    @PutMapping("/edit")
    public R edit(@RequestBody CheckApply device){
        if(service.updateById(device)){
            return R.ok("更新成功！");
        }
        return error("edit error");
    }
}
